﻿Chenxin.UI.ShowDetailPreliminaryPage = Chenxin.extend(Chenxin.UI.PageCommon,{
    autoInitForm: false,
    actionUrl:"/service/logic/ShowListPreliminary.ashx",
    loadinfo: function(callback,scope) {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async:false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentPreliminary = data;
                    if(callback){
                        callback.call(scope);
                    }
                }
            }
        });
    },
    loadCustomer: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'searchCustomer',modelid: this.currentId},
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentCustomer = data;
                }
            }
        });
    },
    initEvent:function(){
        var _this = this;
	
        if (_this.currentId != $("#ctl00_main_hidRecordId").val()) {
            _this.currentId = $("#ctl00_main_hidRecordId").val();
            _this.loadinfo();
        }
            
        //预审回复
        $('#aReplyPre').click(function(){
            _this.loadCustomer();
            _this.showReplyPre();
        });

        //预约贷款
        $('#aApplyLoan').click(function(){
            _this.showApplyLoan();
        });

        //预约回复
        $('#aReplyLoan').click(function(){
            _this.loadCustomer();
            _this.showReplyLoan();
        });

        /*************事件：关闭*************/
        $('#aClose').live('click', function() {
            window.close();
        });
    },
    /**
    *预审回复
    */
    showReplyPre:function(){
        var _this = this;

        if (!this.ReplyPreForm) {
            this.ReplyPreForm = new Chenxin.UI.ReplyPreForm({
                scope: _this,
                alwaysCheckPermit: true,
                afterGetFormJson:function(json){
                    delete json.HouseCode;
                    delete json.Address;
                    delete json.BuildingArea;
                    delete json.BuildingType;
                    delete json.CompleteYear;
                    delete json.Total_Floor;
                    delete json.SalePrice_T;
                    delete json.LoanTotalMoney;
                },
                saveSucc:function(){
                    window.location.reload();
			    }
            });
        }
        this.ReplyPreForm.op = "replypreliminary";
        if(this.ReplyPreForm.show(this.ReplyPreForm.op, { currentId: _this.currentId })) {
            this.ReplyPreForm.reset();
            var _data = {};
            var _customer = this.currentCustomer;
            Chenxin.apply(_data,this.currentPreliminary);
            this.ReplyPreForm.fitData(_data);
            this.ReplyPreForm.setTitle('预审回复');
            this.ReplyPreForm.grid.clear();
            this.ReplyPreForm.grid.render(_customer);
        }
    },

    /**
    *预约贷款
    */
    showApplyLoan: function() {
        var _this = this;
        
        if (!this.ApplyLoanForm) {
            this.ApplyLoanForm = new Chenxin.UI.ApplyLoanForm({
                scope: _this,
                alwaysCheckPermit: true,
                afterGetFormJson:function(json){
                    json.LoanApplyDate = json.LoanApplyDate;
                    delete json.HouseCode;
                    delete json.Address;
                },
                saveSucc:function(){
                    window.location.reload();
			    }
            });
        }
        this.ApplyLoanForm.op = "addloan";
        if(this.ApplyLoanForm.show(this.ApplyLoanForm.op, { currentId: _this.currentId })) {
            this.ApplyLoanForm.reset();
            var _data = {};
            Chenxin.apply(_data,this.currentPreliminary);
            //delete _data.OrderPlace;
            this.ApplyLoanForm.fitData(_data);
            this.ApplyLoanForm.setTitle('预约贷款');
        }
    },
    /**
    *预约回复
    */
    showReplyLoan: function() {
       var _this = this;
        
        if (!this.ReplyLoanForm) {
            this.ReplyLoanForm = new Chenxin.UI.ReplyLoanForm({
                scope: _this,
                alwaysCheckPermit: true,
                afterGetFormJson:function(json){
                    delete json.HouseCode;
                    delete json.Address;
                    delete json.BuildingArea;
                    delete json.BuildingType;
                    delete json.CompleteYear;
                    delete json.Total_Floor;
                    delete json.SalePrice_T;
                    delete json.LoanTotalMoney;
                },
                saveSucc:function(){
                    window.location.reload();
			    }
            });
        }
        this.ReplyLoanForm.op = "replyloan";
        if(this.ReplyLoanForm.show(this.ReplyLoanForm.op, { currentId: _this.currentId })) {
            this.ReplyLoanForm.reset();
            var _data = {};
            var _customer = this.currentCustomer;
            Chenxin.apply(_data,this.currentPreliminary);
            this.ReplyLoanForm.fitData(_data);
            this.ReplyLoanForm.setTitle('预约回复');
            this.ReplyLoanForm.grid.clear();
            this.ReplyLoanForm.grid.render(_customer);
        }
    },
    initComponent: function() {
        Chenxin.UI.ShowDetailPreliminaryPage.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
    var showdetailpreliminarypage = new Chenxin.UI.ShowDetailPreliminaryPage();
});
